#!/bin/bash
#
# Symlink the ctl commands
DEST_DIR=${1:-/opt/gitlab}

usr_bin_symlinks=(
  "${DEST_DIR}/bin/gitlab-ctl"
  "${DEST_DIR}/bin/gitlab-rake"
  "${DEST_DIR}/bin/gitlab-rails"
  "${DEST_DIR}/bin/gitlab-psql"
  "${DEST_DIR}/embedded/bin/gitlab-pg-ctl"
  "${DEST_DIR}/bin/gitlab-geo-psql"
  "${DEST_DIR}/bin/gitlab-backup"
  "${DEST_DIR}/bin/gitlab-redis-cli"
)

error_exit()
{
  echo "${1:-"Unknown Error"}" 1>&2
  exit 1
}

create_symlinks()
{
  for symlink in "${usr_bin_symlinks[@]}"
  do
    if [ -f $symlink ]; then
      ln -sf $symlink /usr/bin || error_exit "Failed to create symlinks in /usr/bin"
    fi
  done
}

create_symlinks
